
char* GetProcessName( ) {
	static char acProcessName[256];
	int iFd =  -1;
	int iPid = getpid();
	
	sprintf(acProcessName, "/proc/%d/cmdline", pid);
	iFd = open(acProcessName, O_RDONLY);
	if(iFd < 0)	 {
		strcpy(acProcessName, "???");
	}
	else {
		int len = read(iFd, acProcessName, sizeof(acProcessName)-1);
		acProcessName[len] = 0;
		close(iFd);
	}
	
	return acProcessName;
}



int GetCpuNum() {
	return sysconf(_SC_NPROCESSORS_CONF);
}


long long GetPhysMemMB() {
	
	return ((long long)sysconf(_SC_PAGESIZE) * (long long)sysconf(_SC_PHYS_PAGES))/(long long)(1024*1024) ;
}

long long GetFreeMemMB() {
	return (long long)sysconf(_SC_PAGESIZE) * (long long)sysconf(_SC_AVPHYS_PAGES)/(long long)(1024*1024) ;
}



int AQ_Daemon(int nochdir, int noclose)
{
    int fd;

    switch (fork()) {
    case -1:
        return (-1);
    case 0:
        break;
    default:
        _exit(0);
    }

    if (setsid() == -1)
        return (-1);

    if (!nochdir)
        chdir("/");

    if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
        dup2(fd, STDIN_FILENO);
        dup2(fd, STDOUT_FILENO);
        dup2(fd, STDERR_FILENO);
        if (fd > 2)
            close (fd);
    }
    return (0);
}


